package com.googlecode.horncomb.organ.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Table;

import org.springframework.util.StringUtils;

import com.googlecode.horncomb.organ.Relation;
import com.googlecode.horncomb.organ.RelationPoint;

/**
 * @author Daniel
 */
@Entity
@Table(name = "HCB_ORGN_RELATION")
@MappedSuperclass
public class DefaultRelation<SourceType extends RelationPoint, TargetType extends RelationPoint>
		implements Relation<SourceType, TargetType> {
	private static final long serialVersionUID = 8059465745518325560L;
	private String id;
	public String nature;
	private String category;
	private String view;
	private SourceType source;
	private TargetType target;
	private String dualRelationId;

	private String state;
	private Date created;
	private Date lastUpdated;

	/**
	 * @return the id
	 */
	@Id
	@Column(name = "ID_")
	public String getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(String id) {
		this.id = id;
	}

	/**
	 * @return the natureType
	 */
	@Column(name = "NATURE_")
	public String getNature() {
		return nature;
	}

	/**
	 * @param natureType the natureType to set
	 */
	public void setNature(String natureType) {
		this.nature = natureType;
	}

	/**
	 * @return the category
	 */
	@Column(name = "CATEGORY_")
	public String getCategory() {
		return category;
	}

	/**
	 * @param category
	 *            the category to set
	 */
	public void setCategory(String category) {
		this.category = category;
	}

	/**
	 * @return the view
	 */
	@Column(name = "VIEW_")
	public String getView() {
		return view;
	}

	/**
	 * @param view
	 *            the view to set
	 */
	public void setView(String view) {
		this.view = view;
	}

	/**
	 * @return the source
	 */
	@Column(name = "SOURCE_")
	public SourceType getSource() {
		return source;
	}

	/**
	 * @param source
	 *            the source to set
	 */
	public void setSource(SourceType source) {
		this.source = source;
	}

	/**
	 * @return the target
	 */
	@Column(name = "TARGET_")
	public TargetType getTarget() {
		return target;
	}

	/**
	 * @param target
	 *            the target to set
	 */
	public void setTarget(TargetType target) {
		this.target = target;
	}

	/**
	 * @return the dualRelationId
	 */
	public String getDualRelationId() {
		return dualRelationId;
	}

	/**
	 * @param dualRelationId
	 *            the dualRelationId to set
	 */
	public void setDualRelationId(String dualRelationId) {
		this.dualRelationId = dualRelationId;
	}

	/**
	 * @return the state
	 */
	@Column(name = "STATE_")
	public String getState() {
		return state;
	}

	/**
	 * @param state
	 *            the state to set
	 */
	public void setState(String state) {
		this.state = state;
	}

	/**
	 * @return the created
	 */
	@Column(name = "CREATED_")
	public Date getCreated() {
		return created;
	}

	/**
	 * @param created
	 *            the created to set
	 */
	public void setCreated(Date created) {
		this.created = created;
	}

	/**
	 * @return the lastUpdated
	 */
	@Column(name = "LST_UPD_")
	public Date getLastUpdated() {
		return lastUpdated;
	}

	/**
	 * @param lastUpdated
	 *            the lastUpdated to set
	 */
	public void setLastUpdated(Date lastUpdated) {
		this.lastUpdated = lastUpdated;
	}

	/**
	 * {@inheritDoc}
	 */
	public boolean isBidirection() {
		return StringUtils.hasText(this.getDualRelationId());
	}
}
